#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>

using namespace std;

bool searchMatrix(vector<vector<int>>& matrix, int target) 
{
    if (matrix.empty() || matrix[0].empty()) 
    {
        return false;
    }

    int m = matrix.size();
    int n = matrix[0].size();

    int left = 0, right = m * n - 1;

    while (left <= right) 
    {
        int mid = (right + left) / 2;
        int mid_value = matrix[mid / n][mid % n];

        if (mid_value == target) 
        {
            return true;
        }
        else if (mid_value < target) 
        {
            left = mid + 1;
        }
        else 
        {
            right = mid - 1;
        }
    }

    return false;
}

int main() 
{
    int m, n;
    cin >> m >> n;

    vector<vector<int>> matrix(m, vector<int>(n));

    for (int i = 0; i < m; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            cin >> matrix[i][j];
        }
    }

    int t;
    cin >> t;

    for (int i = 0; i < t; ++i) 
    {
        int target;
        cin >> target;

        bool result = searchMatrix(matrix, target);

        cout << (result ? "true" : "false") << endl;
    }

    return 0;
}
